from masonite.commands import Command
from app.traits.MyControllerTrait import MyControllerTrait
from app.traits.MyModelTrait import MyModelTrait
import json
import hashlib
import crypt
import random
from app.models.AdminUser import AdminUser
import datetime
from app.models.AdminPermission import AdminPermission
from app.models.AdminMenu import AdminMenu
from config.database import DB
from masoniteorm.collection import Collection
from app.models.AdminRolePermission import AdminRolePermission
from app.models.AdminConfig import AdminConfig
from app.models.AdminRole import AdminRole
import datetime
from app.models.AdminUserLoginLog import AdminUserLoginLog
from masonite.facades import Cache
import os
from app.my_package.MyPackage import (MyValidator, MyValidatorLanguage)
import re
from masonite.facades import Config


class TestCommand(Command):
    """
    this is a test command

    my:test
    """

    def __init__(self, application):
        super().__init__()
        self.app = application

    def handle(self):
        # do whatever you want !

        self.info("test command !")

        data = {
            'username': 'test',
            'age': 18
        }
        # self.info(json.dumps(data))

        # account = "myadmin"
        # password = 'myadmin'
        # adminUser = AdminUser.where("account", account).first()
        # print(adminUser.account)
        # print(type(adminUser.all()))
        # print(adminUser.to_json())

        # print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

        # adminPermissions = AdminPermission.where({'id': '>2'}).get()
        # sql = AdminPermission.where('id', '>', 2).to_sql()

        """
        table = AdminMenu.get_table_name()
        where = ''
        column = '*'
        page = 1
        limit = 10
        order = 'id DESC'
        titles = AdminMenu.get_title()
        #table, where, column = '*', page = 1, limit = 10, order = "id DESC"
        total, admin_menus = MyModelTrait.search_for_show(table, where, column, page, limit, order)
        for index, admin_menu in enumerate(admin_menus):
            print(admin_menu['is_show'])
            admin_menus[index]['is_show'] = AdminMenu.FIELDS['is_show'][admin_menu['is_show']]
            admin_menus[index]['pid'] = titles[admin_menu['pid']]
            print(admin_menus[index])
        """

        param = '127.0.0.1'
        # print(MyValidator.phone_number(13512345678))
        # print(MyValidator.is_integer(123.12))
        # print(MyValidator.is_float(123))
        # print(MyValidator.alpha(param))
        # print(MyValidator.alpha_dash(param))
        # print(MyValidator.alpha_num(param))
        # print(MyValidator.is_cn(param))
        # print(MyValidator.ch_alpha(param))
        # print(MyValidator.ch_alpha_num(param))
        # print(MyValidator.is_lower(param))
        # print(MyValidator.is_upper(param))
        # print(MyValidator.between(param, 1, 4))
        # print(MyValidator.boolean(param))
        # print(MyValidator.digits_between(param, 1,3))
        # print(MyValidator.email(param))
        # print(MyValidator.gt(param, 2))
        # print(MyValidator.ipv4(param))
        # print(isinstance(-123, int))
        # print(len('你好'))
        # print(MyValidatorLanguage.get_message('is_integer', 'zh'))
        # print(MyValidatorLanguage.get_message('digits_between', 0, 3, language='zh'))

        b, m = MyValidator.digits_between('', 3, 8)
        print(b)
        print(m)
        print(Config.get('application.app_name'))
